package com.andreas.serviceImp;

import com.andreas.mapper.BookMapper;
import com.andreas.mapper.EvaluationMapper;
import com.andreas.mapper.MemberMapper;
import com.andreas.pojo.Book;
import com.andreas.pojo.Evaluation;
import com.andreas.pojo.Member;
import com.andreas.service.EvaluationService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author andreaszhou
 * @ClassName EvaluationServiceImpl
 * @Description TODO
 * @date 2021/1/20 17:53
 * @Version 1.0
 */
@Service
@Transactional(propagation = Propagation.NOT_SUPPORTED,readOnly = true)
public class EvaluationServiceImpl implements EvaluationService {
    @Resource
    private EvaluationMapper evaluationMapper;
    @Resource
    private BookMapper bookMapper;
    @Resource
    private MemberMapper memberMapper;

    @Override
    public List<Evaluation> showEvaluationService(int bookId) {
        Book book = bookMapper.selectById(bookId);
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("book_id",bookId);
        queryWrapper.eq("state","enable");
        queryWrapper.orderByDesc("create_time");
        List<Evaluation> evaluationList = evaluationMapper.selectList(queryWrapper);
        for (Evaluation temp:evaluationList
             ) {
            int memberId = temp.getMemberId();
            Member member = memberMapper.selectById(memberId);
            temp.setBook(book);
            temp.setMember(member);
        }
        return evaluationList;
    }
}
